package com.yxcz.serviceImpl;

import java.util.ArrayList;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.yxcz.dao.SupplierDAO;
import com.yxcz.model.Supplier;
import com.yxcz.service.SupplierService;

@Service
public class SupplierServiceImpl implements SupplierService {
	
	@Resource
	private SupplierDAO supplierDAO;

	@Override
	public ArrayList<Supplier> list() {
		return supplierDAO.list();
		
	}

	@Override
	public Supplier find(Integer id) {
		return supplierDAO.find(id);
	}

	@Override
	public void delete(Integer id) {
		supplierDAO.delete(supplierDAO.find(id));
		
	}

	@Override
	public void add(Supplier supplier) throws Exception {
		supplierDAO.add(supplier);
		
	}
	
	@Override
	public void addAll(String[][] suppliers) throws Exception {
		
		for (String[] string : suppliers) {
			Supplier supplier = new Supplier();
			supplier.setCompanyName(string[0]);
			supplier.setShortName(string[1]);
			supplier.setAccount(string[2]);
			supplier.setTaxNumber(string[3]);
			supplier.setPayType(string[4]);
			supplier.setAddress(string[5]);
			supplier.setContacts(string[6]);
			supplier.setEmail(string[7]);
			supplier.setPhone(string[8]);
			supplier.setMobilePhone(string[9]);
			supplier.setFax(string[10]);
			supplier.setQq(string[11]);
			supplier.setEtc(string[12]);
			supplierDAO.add(supplier);
			
		}
		
	}

	@Override
	public void update(Supplier supplier) {
		
		supplierDAO.save(supplier);
		
	}




}
